
#include "Data/User.h"

#include "NewsQuery.h"


namespace TC
{
	namespace Request
	{

		void NewsQuery::queryAll(quint64 groupId)
		{
			if (status() == Status::Communicating)
				return;
			AbstractRemoteProcedure::get("discover/news/queryAll",
			{
				{ "signature", Data::User::instance()->signature() },
				{ "groupId", groupId },
			});
		}

		void NewsQuery::onDataReady(QDataStream &stream)
		{
			bool result;
			stream >> result;
			if (result)
			{
				QList<QVariantMap> vms;
				stream >> vms;
				news.clear();
				for (auto &v : vms)
				{
					news.append(v);
				}
				setOk();
			}
			else
			{
				setFailed();
			}
		}

	}
}